//491. 递增子序列


//我的从后向前递归,然后用set去重复

/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var findSubsequences = function(nums) {

    /**
     * @param {number[]} nums
     * @return {number[][]}
     */
    function find(nums){
        if(nums.length===1) return [[nums[0]]]
        let child = find(nums.slice(0,nums.length-1))
        let last = nums[nums.length-1]
        child.forEach((a)=>{
            if(last>=a[a.length-1]) {
                //复制原来的一份
                let b = JSON.parse(JSON.stringify(a))
                a.push(last)
                child.push(b)

            }
        })
        child.push([last])
        return child
    }
    if(nums.length===0) return []
    let r = find(nums)
    let set = new Set()
    r.forEach((e)=>{
        if(e.length>=2){
            set.add(e.join(','))
        }
    })
    let ans =[]
    for(const it of set){
        let a = it.split(',')
        ans.push(a.map((e)=>{
            return e*1
        }))
    }
    return ans
};

let a = findSubsequences([])
console.log(a)


//题解是采取枚举所有的字串,然后判断是否是
//去重方法是采取计算每个数组的hash值